package com.hitown.controller.dxhd;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hitown.model.dxhd.DxhdRygkZdrysmzdt;
import com.hitown.service.dxhd.DxhdRygkZdrysmzdtService;
import com.hitown.util.Params;
import com.hitown.util.R;
import com.hitown.util.StringUtils;
import com.hitown.util.UUIDUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collection;
import java.util.Date;

/**
 * <p>
 * 人员管控-重点人员实名制动态信息 前端控制器
 * </p>
 *
 * @author menu
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/dxhd-rygk-zdrysmzdt")
public class DxhdRygkZdrysmzdtController {

    @Autowired
    private DxhdRygkZdrysmzdtService dxhdRygkZdrysmzdtService;

    @ApiOperation(value = "分页查询")
    @RequestMapping("selectPage")
    public R selectPage(@ApiIgnore @RequestBody Params<DxhdRygkZdrysmzdt> params){
        Page<DxhdRygkZdrysmzdt> page = new Page<>(params.getCurrent(),params.getSize());
        QueryWrapper<DxhdRygkZdrysmzdt> wrapper =new QueryWrapper<>();
        wrapper.select("ID","(select content from t_dictionary t where type='ZJDM' and id = CYZJDM) CYZJMC","CYZJDM","ZJHM","GMSFHM","XM",
                "(select content from t_dictionary t where type='XB' and id = XBDM) XBMC","XBDM","(select content from t_dictionary t where type='GJ' and id = GJDM) GJMC","GJDM",
                "(select content from t_dictionary t where type='MZ' and id = MZDM) MZMC","MZDM","DTXXLX","MHCX_HBH","MHCX_ZWH","MHCX_CF_RQ","MHCX_CF_SJ","MHCX_CF_QFJCDM","MHCX_DD_RQ",
                "MHCX_DD_SJ","MHCX_DD_QFJCDM","TLCX_CC","TLCX_CXH","TLCX_ZWH","TLCX_CF_RQ","TLCX_CF_SJ","TLCX_CF_CZ","TLCX_DD_RQ","TLCX_DD_SJ","TLCX_DD_CZ","GLKY_KYZ","GLKY_KYBH",
                "GLKY_ZWH","GLKY_CF_RQ","GLKY_CF_SJ","GLKY_CF_KYZ","GLKY_DD_RQ","GLKY_DD_SJ","GLKY_DD_KYZ","LDCX_LDH","LDCX_CF_RQ","LDCX_CF_SJ","LDCX_CF_MT","LDCX_DD_RQ","LDCX_DD_SJ",
                "LDCX_DD_MT","GAJCZ_JCZBM","GAJCZ_JCZWZ","GAJCZ_JYSJ","GAJCZ_CRLX","LGZS_LGBM","LGZS_LGMC","LGZS_RZFH","LGZS_RZSJ","LGZS_TFSJ","WBSW_YYCSDM","WBSW_YYCS_DWMC",
                "WBSW_YYCS_DZMC","WBSW_KSSJ","WBSW_JSSJ","RXSB_SBLX","RXSB_SPSBBM","RXSB_SBMC","RXSB_JSFX","RXSB_SBDZ","RXSB_ZPSJ","RXSB_TPURL","DQJD","DQWD","CJSJ","XXRKSJ",
                "CTU","CTM","UTU","UTM");
        //姓名
        if(!StringUtils.isEmpty(params.getEntity().getXm())){
            wrapper.like("XM", params.getEntity().getXm());
        }

        //公民身份号码
        if(!StringUtils.isEmpty(params.getEntity().getGmsfhm())) {
            wrapper.eq("GMSFHM",params.getEntity().getGmsfhm());

        }
        //性别代码
        if(!StringUtils.isEmpty(params.getEntity().getXbdm())) {
            wrapper.eq("XBDM",params.getEntity().getXbdm());

        }
        IPage<DxhdRygkZdrysmzdt> pageVo = dxhdRygkZdrysmzdtService.page(page,wrapper);
        return R.ok().put("data",pageVo);

    }


    @ApiOperation(value = "根据id查询记录")
    @RequestMapping("getById")
    public R getById(@RequestParam String Id){
        DxhdRygkZdrysmzdt result = dxhdRygkZdrysmzdtService.getById(Id);
        return R.ok().put("data",result);

    }

    @ApiOperation(value = "保存单条记录")
    @PostMapping("save")
    public R save(@RequestBody DxhdRygkZdrysmzdt entit){
        entit.setId(UUIDUtils.getUUID());
        Boolean result = dxhdRygkZdrysmzdtService.save(entit);
        return R.ok().put("data",result);
    }


    @ApiOperation(value = "批量保存")
    @RequestMapping("saveBatch")
    public R saveBatch(@RequestBody Collection<DxhdRygkZdrysmzdt> entityList){
        Boolean result = dxhdRygkZdrysmzdtService.saveBatch(entityList);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据 ID 选择修改")
    @RequestMapping("updateById")
    public R updateById(@RequestBody DxhdRygkZdrysmzdt entit){
        entit.setUtm(new Date());
//        Boolean result = dxhdRygkZdrysmzdtService.updateById(entit);
        return dxhdRygkZdrysmzdtService.updateDxhdRygkZdrysmzdt(entit);

    }


    @ApiOperation(value = "根据ID 批量更新")
    @RequestMapping("updateBatchById")
    public R updateBatchById(@RequestBody Collection<DxhdRygkZdrysmzdt> entityList){
        Boolean result = dxhdRygkZdrysmzdtService.updateBatchById(entityList);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据 ID 删除")
    @RequestMapping("removeById")
    public R removeById(@RequestParam String Id){
        Boolean result = dxhdRygkZdrysmzdtService.removeById(Id);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "删除（根据ID 批量删除）")
    @RequestMapping("removeByIds")
    public R removeByIds(@RequestBody Collection<String> Ids){
        Boolean result = dxhdRygkZdrysmzdtService.removeByIds(Ids);
        return R.ok().put("data",result);
    }
}

